home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
pcl_src.zoo
/
env.lsp
< prev
next >
Wrap
Lisp/Scheme
|
1992-07-09
|
16KB
|
407 lines
;;;-*-Mode:LISP; Package:(PCL (LISP WALKER)); Base:10; Syntax:Common-lisp -*-
;;;
;;; *************************************************************************
;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
;;; All rights reserved.
;;;
;;; Use and copying of this software and preparation of derivative works
;;; based upon this software are permitted. Any distribution of this
;;; software or derivative works must comply with all applicable United
;;; States export control laws.
;;;
;;; This software is made available AS IS, and Xerox Corporation makes no
;;; warranty about the software, its performance or its conformity to any
;;; specification.
;;;
;;; Any person obtaining a copy of this software is requested to send their
;;; name and post office or electronic mail address to:
;;; CommonLoops Coordinator
;;; Xerox PARC
;;; 3333 Coyote Hill Rd.
;;; Palo Alto, CA 94304
;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
;;;
;;; Suggestions, comments and requests for improvements are also welcome.
;;; *************************************************************************
;;;
;;; Basic environmental stuff.
;;;
(in-package 'pcl)
#+Lucid
(progn
(defun pcl-arglist (function &rest other-args)
(let ((defn nil))
(cond ((and (fsc-instance-p function)
(generic-function-p function))
(generic-function-pretty-arglist function))
((and (symbolp function)
(fboundp function)
(setq defn (symbol-function function))
(fsc-instance-p defn)
(generic-function-p defn))
(generic-function-pretty-arglist defn))
(t (apply (original-definition 'sys::arglist)
function other-args)))))
(redefine-function 'sys::arglist 'pcl-arglist)
)
;;;
;;;
;;;
(defgeneric describe-object (object stream))
#-Genera
(progn
(defun pcl-describe (object #+Lispm &optional #+Lispm no-complaints)
(let (#+Lispm (*describe-no-complaints* no-complaints))
#+Lispm (declare (special *describe-no-complaints*))
(describe-object object *standard-output*)
(values)))
(defmethod describe-object (object stream)
(let ((*standard-output* stream))
(funcall-compiled (original-definition 'describe) object)))
(redefine-function 'describe 'pcl-describe)
)
(defmethod describe-object ((object slot-object) stream)
(format stream "~%~S is an instance of class ~S:" object (class-of object))
(describe-object-slots object stream))
(defmethod describe-object-slots
((object slot-object)
stream
&key
(slots-to-inspect (slots-to-inspect (class-of object) object))
&allow-other-keys)
"Display the value of all the slots-to-inspect on this object."
(let* ((max-slot-name-length 0)
(instance-slotds ())
(class-slotds ())
(other-slotds ()))
(declare (type index max-slot-name-length))
(flet ((adjust-slot-name-length (name)
(setq max-slot-name-length
(the index
(max max-slot-name-length
(length (the simple-string
(symbol-name name)))))))
(describe-slot (name value &optional (allocation () alloc-p))
(if alloc-p
(format stream
"~% ~A ~S ~VT "
name allocation (+ max-slot-name-length 7))
(format stream
"~% ~A~VT "
name max-slot-name-length))
(prin1 value stream)))
;; Figure out a good width for the slot-name column.
(dolist (slotd slots-to-inspect)
(adjust-slot-name-length (slot-definition-name slotd))
(case (slot-definition-allocation slotd)
(:instance (push slotd instance-slotds))
(:class (push slotd class-slotds))
(otherwise (push slotd other-slotds))))
(setq max-slot-name-length
(the index (min (the index (+ max-slot-name-length 3)) 30)))
(when instance-slotds
(format stream "~% The following slots have :INSTANCE allocation:")
(dolist (slotd (nreverse instance-slotds))
(describe-slot (slot-definition-name slotd)
(slot-value-or-default
object (slot-definition-name slotd)))))
(when class-slotds
(format stream "~% The following slots have :CLASS allocation:")
(dolist (slotd (nreverse class-slotds))
(describe-slot (slot-definition-name slotd)
(slot-value-or-default
object (slot-definition-name slotd)))))
(when other-slotds
(format stream "~% The following slots have allocation as shown:")
(dolist (slotd (nreverse other-slotds))
(describe-slot (slot-definition-name slotd)
(slot-value-or-default
object (slot-definition-name slotd))
(slot-definition-allocation slotd))))
(values))))
(defmethod slots-to-inspect ((class slot-class) (object slot-object))
(class-slots class))
(defvar *describe-generic-functions-as-objects-p* nil)
(defmethod describe-object ((fun standard-generic-function) stream)
(format stream "~A is a generic function.~%" fun)
(format stream "Its arguments are:~% ~S~%"
(generic-function-pretty-arglist fun))
(if *describe-generic-functions-as-objects-p*
(describe-object-slots fun stream)
(progn
(format stream "Its methods are:")
(dolist (meth (generic-function-methods fun))
(format stream "~2%**** ~{~S ~}~:S =>~%"
(method-qualifiers meth)
(unparse-specializers meth))
(describe-object meth stream)))))
;;;
;;;
;;;
(defvar *describe-classes-as-objects-p* nil)
(defmethod describe-object ((class class) stream)
(flet ((pretty-class (c) (or (class-name c) c)))
(macrolet ((ft (string &rest args) `(format stream ,string ,@args)))
(ft "~&~S is a class, it is an instance of ~S.~%"
class (pretty-class (class-of class)))
(let ((name (class-name class)))
(if name
(if (eq class (find-class name nil))
(ft "Its proper name is ~S.~%" name)
(ft "Its name is ~S, but this is not a proper name.~%" name))
(ft "It has no name (the name is NIL).~%")))
(ft "The direct superclasses are: ~:S, and the direct~%~
subclasses are: ~:S. "
(mapcar #'pretty-class (class-direct-superclasses class))
(mapcar #'pretty-class (class-direct-subclasses class)))
(if (class-finalized-p class)
(ft "The class precedence list is:~%~S~%"
(mapcar #'pretty-class (class-precedence-list class)))
(ft "The class is not finalized.~%"))
(ft "There are ~D methods specialized for this class."
(length (the list (specializer-direct-methods class))))))
(when *describe-classes-as-objects-p*
(describe-object-slots class stream)))
(declaim (ftype (function (T &optional T) (values T T symbol))
parse-method-or-spec))
(defun parse-method-or-spec (spec &optional (errorp t))
(declare (values generic-function method method-name))
(let (gf method name temp)
(if (method-p spec)
(setq method spec
gf (method-generic-function method)
temp (and gf (generic-function-name gf))
name (if temp
(intern-function-name
(make-method-spec temp
(method-qualifiers method)
(unparse-specializers
(method-specializers method))))
(make-symbol (format nil "~S" method))))
(m